/**
 * Description:该类主要用于为页面装载组件和控件，并对组件进行初始化
 * 事件: pageComplete  - 如果HandleClass拥有该方法, 则调用
 */
function Application() {}

Application.inherit(Component);

/**
 * 初始化函数
 */
Application.prototype.init = function (g_sPath) {
	this._path = g_sPath;
	this.setType("Application");
	this.setRoot(this);
	this.setComponent(this);
    this.setAttribute({id:Math.uuid()});

    this._paramDefine = {}; //参数定义
    this._param = {}; //组件参数
    this._handlerDefine = {}; //输入接口定义
    this._cHandlerDefine = {}; //输出接口定义
    this._layoutdata = {}; //组件布局信息
    this._exCHandler = {}; //输出接口排除组件

	Application.base.init.call(this);
	//开始加载,暂不能使用异步加载方式，否则二代证事件机制无效，原因不明有待详细分析
//    this.beginLoad();
    var that = this;

    this.load(true, function(){
        //that.load();
        if (that.getHandleClass() && that.getHandleClass().pageComplete) {
            that.getHandleClass().pageComplete(that);
        }
    });
}

Application.prototype.create = function() {
    this._html = $("body")[0];
}

/**
 * 设置标题
 */ 
Application.prototype.setTitle = function(sTitle) {
	if(sTitle) {
		document.title = sTitle;
	}
}

/**
 * 异步加载, 容器内显示等待
 */
Application.prototype.beginLoad = function() {
    if (!this._loadingDom) this.createLoadDom();
    $(this._html).append(this._loadingDom);
}

/**
 * 结束加载, 取消等待
 */
Application.prototype.endLoad = function() {
    try {
    	$(this._loadingDom).detach();
    } catch(e) {
    }
}

/**
 * 创建加载节点
 */
Application.prototype.createLoadDom = function() {
    var loadingDom = $(
            "<div class='contloading'>" +
            "<div class='loading'>加载中...</div>" +
            "</div>");
    var ch = document.documentElement.clientHeight;
    var cw = document.documentElement.clientWidth;
    $(loadingDom).width(cw);
    $(loadingDom).height(ch);
    $(".loading", loadingDom).css({
        left:(cw-80)/2,
        top:(ch-40)/2
    });
    this._loadingDom = loadingDom;
}